-- Decompiled with the Synapse X Luau decompiler.

local ClientOHOH = _G.ClientOHOH;
local TweenService = game:GetService("TweenService")
local InitInst=nil
 InitInst = {
	GetInst = function(p1, p2)
		if type(p2) ~= "table" then
			if type(p2) == "string" then
				--print("p1->p2",p1,p2)
				return p1:WaitForChild_Loop(p2);
			else
				return;
			end;
		end;
		local v2 = {};
		for v3, v4 in pairs(p2) do
			v2[v3] = InitInst.GetInst(p1, v4);
		end;
		return v2;
	end,



	-- GetInst2 = function(p1, p2)
	-- 	if type(p2) ~= "table" then
	-- 		if type(p2) == "string" then
	-- 			--print("p1->p2",p1,p2)
	-- 			return p1:WaitForChild_Loop(p2);
	-- 		else
	-- 			return;
	-- 		end;
	-- 	end;
	-- 	local v2 = {};
	-- 	for v3, v4 in pairs(p2) do
	-- 		v2[v3] = InitInst.GetInst(p1, v4);
	-- 	end;
	-- 	return v2;
	-- end,


	GetInst2 = function(p1, p2)
		if type(p2) ~= "table" then
			if type(p2) == "string" then
				local obj=p1:WaitForChild_Loop(p2)
				return obj.Value
			else
				return;
			end;
		end;
		local v2 = {};
		for v3, v4 in pairs(p2) do
			v2[v3] = InitInst.GetInst2(p1, v4);
		end;
		return v2;
	end
};


local M = ClientOHOH.class.new(script, ClientOHOH.files.GameObject());
local tweenSpeed = 0.1

function M.new(self)
	return M(self);
end;
function M.ctor(self, p5)
	M.super.ctor(self, p5);
	if self.insts then
		self:FullInsts()
	end;
	local rootTween = self.main_inst:FindFirstChild("rootTween")
	if rootTween then
		self.tweenSize=self.main_inst.rootTween.Value.Size
	end

	self.BaseHideEvent=_G.CommonOHOH.load.Connect().new()
	self.BaseShowEvent=_G.CommonOHOH.load.Connect().new()

end;


function M.FullInsts(self)
		self:Full_1()
end
function M.Full_1(self)
	self.insts = InitInst.GetInst(self, self.insts);
end
function M.Full_2(self)
	self.insts = InitInst.GetInst2(self, self.insts);
end


--普通填充
function M.InitUiInst(self,uiObj,pathStr)
	if type(pathStr) ~= "table" then
		if type(pathStr) == "string" then
			return ClientOHOH:GetPath_Loop(pathStr,uiObj)
		else
			return;
		end;
	end;
	local v2 = {};
	for v3, v4 in pairs(pathStr) do
		v2[v3] = self:InitUiInst(uiObj, v4);
	end;
	return v2;
end


--Value 填充
function M.InitUiInst2(self,uiObj,pathStr)
	if type(pathStr) ~= "table" then
		if type(pathStr) == "string" then
			return ClientOHOH:GetPath_Loop(pathStr,uiObj).Value
		else
			return;
		end;
	end;
	local v2 = {};
	for v3, v4 in pairs(pathStr) do
		v2[v3] = self:InitUiInst2(uiObj, v4);
	end;
	return v2;
end


-- function M.GetAbsoluteProperties(self,uiObj)
--     local absolutePosition = uiObj.AbsolutePosition
--     local absoluteSize = uiObj.AbsoluteSize
--     local absoluteRotation = uiObj.Rotation

-- 	 -- 遍历父级对象，直到找到 ScreenGui
-- 	 local parent = uiObj.Parent
-- 	 while parent and not parent:IsA("ScreenGui") do
-- 		 absolutePosition = absolutePosition + parent.AbsolutePosition
-- 		 absoluteRotation = absoluteRotation + parent.Rotation
-- 		 parent = parent.Parent
-- 	 end
	 
-- 	 return absolutePosition, absoluteSize, absoluteRotation
-- end

function M.dtor(self)
	self.main_inst:Destroy();
	M.super.dtor(self);
end;


function M.PlayShowTween(self,...)
	if not self.tweenSize then
		return 
	end
	self.main_inst.rootTween.Value.Size = UDim2.new(0,0,0,0)
	self.main_inst.rootTween.Value.AnchorPoint = Vector2.new(0.5,0.5)
	local tweenInfo = TweenInfo.new(tweenSpeed,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out)
	local transtion = {
		Size = self.tweenSize
	}
	local tw = TweenService:Create(self.main_inst.rootTween.Value,tweenInfo,transtion)
	tw:Play()
end

function M.CloseShowTween(self,...)
	if not self.tweenSize then
		return 
	end
	local tweenInfo = TweenInfo.new(tweenSpeed,Enum.EasingStyle.Cubic,Enum.EasingDirection.In)
	local tw = TweenService:Create(self.main_inst.rootTween.Value,tweenInfo,{Size = UDim2.new(0,0,0,0)})
	tw.Completed:Connect(function(...)
		if self.OnHide then
			self:OnHide(...);
		end;
		self.main_inst.Enabled = false;
		return
	end)
	tw:Play()
end

function M.Show(self,...)
	-- if self.main_inst.Enabled then
	-- 	return
	-- end
	self.BaseShowEvent:Action()

	if not self.main_inst.Enabled then
		self:PlayShowTween()
	end
	
	if self.OnShow then
		self:OnShow(...);
	end;
	self.main_inst.Enabled = true;
	
end;
function M.Hide(self,...)
	-- if not self.main_inst.Enabled then
	-- 	return
	-- end

	if not self.tweenSize then
		if self.OnHide then
			self:OnHide(...);
		end;
		self.main_inst.Enabled = false;
		return
	end
	if self.main_inst.Enabled then
		self:CloseShowTween()
	end
	self.BaseHideEvent:Action()
end;
function M.IsVisible(self)
	return self.main_inst.Enabled;
end;
function M.UpdataStrokeSize(self)
	for v5, v6 in ipairs(self.main_inst:GetChildren()) do

	end;
end;
local CallBackManager = ClientOHOH.load.CallBackManager();
function M.InitUIGridLay(self, scorlling, grid)
	assert(scorlling, "param scorlling frame is nil");
	assert(grid, "param ui grid layout is nil");
	assert(scorlling:IsA("ScrollingFrame"), "param scorlling frame must be a ScorllingFrame");
	assert(grid:IsA("UIGridLayout"), "param ui grid layout must be a UIGridLayout");

	CallBackManager:AddRbxConnect(self, grid.Changed, function(p14, p15)
		if p15 == "AbsoluteCellCount" then
			local v14 = grid.AbsoluteContentSize.X / scorlling.AbsoluteCanvasSize.X;
			local v15 = grid.AbsoluteContentSize.Y / scorlling.AbsoluteCanvasSize.Y;
			local v16 = scorlling.CanvasSize.X.Scale * v14;
			local v17 = scorlling.CanvasSize.Y.Scale * v15;
			if v16 <= scorlling.CanvasSize.X.Scale and v17 <= scorlling.CanvasSize.Y.Scale then
				return;
			end;
			scorlling.CanvasSize = UDim2.fromScale(v16, v17);
			grid.CellSize = UDim2.fromScale(grid.CellSize.X.Scale / v14, grid.CellSize.Y.Scale / v15);
			grid.CellPadding = UDim2.fromScale(grid.CellPadding.X.Scale / v14, grid.CellPadding.Y.Scale / v15);
			
		end;
	end);
end;
function M.InitUIListLay(self, scorlling, ui)
	assert(scorlling, "param scorlling frame is nil");
	assert(ui, "param ui grid layout is nil");
	assert(scorlling:IsA("ScrollingFrame"), "param scorlling frame must be a ScorllingFrame");
	assert(ui:IsA("UIGridLayout"), "param ui grid layout must be a UIGridLayout");
	CallBackManager:AddRbxConnect(self, ui.Changed, function(p19, p20)
		if p20 == "AbsoluteCellCount" then
			local v23 = ui.AbsoluteContentSize.Y / scorlling.AbsoluteCanvasSize.Y;
			local v24 = scorlling.CanvasSize.Y.Scale * v23;
			if v24 <= scorlling.CanvasSize.Y.Scale then
				return;
			end;
			scorlling.CanvasSize = UDim2.fromScale(scorlling.CanvasSize.X.Scale, v24);
			ui.CellSize = UDim2.fromScale(ui.CellSize.X.Scale, ui.CellSize.Y.Scale / v23);
			ui.CellPadding = UDim2.fromScale(ui.CellPadding.X.Scale, ui.CellPadding.Y.Scale / v23);
		end;
	end);
end;
function M.UIStrokeListen(self, p22)

end;
return M;
